<!DOCTYPE html>
<html lang="en">
<head>
    <title>公司管理层-陪同拜访</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=4a6c1b54">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        td {
            position: relative;
        }

        .tryStyle {
            width: 30px;
            height: 14px;
            line-height: 14px;
            font-size: 12px;
            /* top: 0; */
            right: 0;
            position: absolute;
            border-radius: 5px;
            margin-top: 1px;
            background: red;
            color: #fff;
            margin-right: -2px;
            transform: scale(0.8);
        }

        .userStyle {
            background: rgba(34, 139, 238, 0.2);
        }

        .row {
            margin-right: -15px;
            margin-left: 0px;
        }

        .col-lg-6, .col-xs-6, .col-md-6 {
            padding-left: 0;
        }
    </style>
</head>
<body>
<section class="content" id="app">
    <div class="div-td-content-more"><i></i></div>
    <div class="nav-tabs-custom oaReportNav" v-cloak>
        <ul class="nav nav-tabs pull-right" style="margin-bottom: 10px;" v-cloak>
            <li :class="isActive(today)?'active':''"
                @click="refreshData('visitClientCustomer','get_visitClientCompany',today)"><a href="#sales-chart"
                                                                                              data-toggle="tab">今日</a>
            </li>
            <li :class="isActive(yesterday)?'active':''"
                @click="refreshData('visitClientCustomer','get_visitClientCompany',yesterday)"><a href="#sales-chart"
                                                                                                  data-toggle="tab">昨日</a>
            </li>
            <li :class="isActive(thisWeek)?'active':''"
                @click="refreshData('visitClientCustomer','get_visitClientCompany',thisWeek)"><a href="#sales-chart"
                                                                                                 data-toggle="tab">本周</a>
            </li>
            <li :class="isActive(thisMonth)?'active':''"
                @click="refreshData('visitClientCustomer','get_visitClientCompany',thisMonth)"><a href="#sales-chart"
                                                                                                  data-toggle="tab">本月</a>
            </li>
            <li v-for="(item,i) in tab" :class="isActive(item.time)?'active':''"
                @click="refreshData('visitClientCustomer','get_visitClientCompany',item.time)"><a href="#sales-chart"
                                                                                                  data-toggle="tab">{{i==0?"上月":item.str}}</a>
            </li>
        </ul>
    </div>
    <div style="padding: 0 10px;background: #fff;overflow: hidden" id="visitClientCompany">
        <div style="width: 100%;" class="mScrollBox">
            <table class="table table-bordered text-center table-width">
                <thead>
                <tr>
                    <!--<th style="width:5%">序号</th>-->
                    <th style="width: 10%;text-align: center">大区经理</th>
                    <th style="width: 10%;text-align: center">大区</th>
                    <th style="width: 10%;text-align: center">
                        陪跑区域经理
                    </th>
                    <th style="width: 10%;text-align: center">
                        陪跑客户数量
                    </th>
                    <th style="width: 55%;text-align: center">区域</th>
                </tr>
                </thead>
                <tbody v-cloak>
                <template v-if="visitClientCustomer.list.length>0">
                    <tr v-for="(item,i) in visitClientCustomer.list">
                        <!--<td>{{i+1}}</td>-->
                        <td :rowspan="item.managerNamespan" :class="{hidden: item.managerNamedis}"
                            style="text-align: center">{{item.managerName}}
                        </td>
                        <td :rowspan="item.departNamespan" :class="{hidden: item.departNamedis}"
                            style="text-align: center">{{item.departName}}
                        </td>
                        <td style="text-align: center;" :class="item.entourageName=='无'?'userStyle':''">
                            {{item.entourageName}}<span v-if="item.jobState==-2" class="tryStyle">试岗</span><span
                                v-if="item.jobState==-1" class="tryStyle">试用</span></td>
                        <td v-if="isGo(item)" style="color:#169BD5;cursor: pointer;text-align: center"
                            @click="lookRegionList(item)" :class="item.entourageName=='无'?'userStyle':''">
                            {{item.visitCount}}
                        </td>
                        <td v-else style="text-align: center" :class="item.entourageName=='无'?'userStyle':''">
                            {{item.visitCount}}
                        </td>
                        <td style="text-align: left" :class="item.entourageName=='无'?'userStyle':''">
                            {{item.regionName}}
                        </td>
                    </tr>
                    <tr v-if="visitClientCustomer.list.length!=0">
                        <td>合计</td>
                        <td>-</td>
                        <td>-</td>
                        <td>{{visitClientCustomer.visitCount}}</td>
                        <td>-</td>
                    </tr>
                </template>
                <template v-else>
                    <tr>
                        <td colspan="5">暂无数据</td>
                    </tr>
                </template>
                </tbody>
            </table>
        </div>
    </div>
    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=602456c3"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=6348cbbc"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/highcharts/highcharts.js"></script>
<script type="text/javascript">
    console.log(urlConfig);
    var app = new Vue({
        el: '#app',
        data: {
            currentUser: getCurrentUser(),
            list: [],
            months: [],
            userId: getCurrentUser().id,
            dateTime: $.wyui.page.urlParams.dateTime,
            yesterday: new Date(new Date() - 24 * 60 * 60 * 1000).Format("yyyy-MM-dd"),
            today: new Date().Format("yyyy-MM-dd"),
            hour: new Date().getHours(),
            companyId: $.wyui.page.urlParams.companyId,
            thisMonth: new Date().Format("yyyy-MM"),
            thisWeek: new Date().Format("yyyy-MM-dd") + "-w",
            tab: [],
            isToday: "1",
            visitClientCustomer: {
                time: $.wyui.page.urlParams.dateTime,
                list: [],
                allCount: {"managerCount": "", "visitCount": "", "managerTargetNum": "", "regionManagerNum": ""}
            },
        },
        methods: {
            //获取tab
            getTab: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");
                for (var i = 0; i < 5; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.tab.push(that.insert_flg(dateTime, "-", "4"))
                }
                console.log(that.tab)
            },
            //  查看下属
//            lookRegionList:function (item) {
//                var that = this;
//                url = "/page/reportForm/interview/accompanyInterviewList.html?userId="+item.userId+"&dateTime="+that.visitClientCustomer.time+"&entourage="+item.entourageName;
////                window.open(url + '?userId=' + item.managerId+"&dateTime="+this.dateTime+"&name="+item.managerName, "", "top=50,left=" + (window.screen.width - 10 - 1000) / 2 + ",width=1000,height=600");
//                $.dialog({
//                    content: 'url:'+url,
//                    title: '陪跑列表',
//                    width: 600,
//                    height: 500,
//                    max: false,
//                    min: false,
//                    lock: true
//                });
//            },
            lookRegionList: function (item) {
                var that = this;
                top.closeTabByPageId("ppList");
                top.addTabs({
                    id: 'ppList',
                    title: '陪跑列表',
                    close: true,
                    url: 'reportForm/interview/accompanyInterviewList.html?userId=' + item.userId + "&dateTime=" + that.visitClientCustomer.time + "&entourage=" + item.entourageName
                });
            },
            isActive: function (item) {
                var that = this;
                if (that.visitClientCustomer.time == item) {
                    return true;
                }
            },
            //tab中点击日期刷新对应数据
            refreshData: function (dataType, fun, time) {
                var that = this;
                that[dataType].time = time;
                that[fun]();
            },
            getLastEndMonth: function (beginYearMonth) {
                var strYear = parseInt(beginYearMonth.substr(0, 4), 10);
                var strMonth = parseInt(beginYearMonth.substr(4, 6), 10);
                if (strMonth - 1 == 0) {
                    strYear -= 1;
                    strMonth = 12;
                } else {
                    strMonth -= 1;
                }
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var monthstr = strYear + "" + strMonth;
                return monthstr;
            },
            getMonths: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");
                for (var i = 0; i < 5; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.months.push(that.insert_flg(dateTime, "-", "4"))
                }
            },
            //格式化日期
            insert_flg: function (str, flg, sn) {
                var newstr = "";
                for (var i = 0; i < str.length; i += sn) {
                    var tmp = str.substring(i, i + sn);
                    newstr += tmp + flg;
                }
                newstr = newstr.substr(0, newstr.length - 1);
                var st1 = newstr.substr(2, 2);
                var st2 = newstr.substr(5, 2);
                var newstr3 = st2 + "/" + st1;
                var obj = {str: newstr, time: newstr};
                return obj;
            },
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            //获取合计
            getCount: function (arr, key) {
                var number = 0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number += (arr[i][key] && arr[i][key] != '-' ? arr[i][key] : 0)

                }
                return number;
            },
            //获取陪同拜访客户报表-公司级别
            get_visitClientCompany: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.report.visitCustomer.getManagerByUserId, {
                    "companyId": that.companyId,
                    "dateTime": that.visitClientCustomer.time,
                    "entourageName": that.visitClientCustomer.entourageName
                }, function (data) {
                    that.visitClientCustomer.list = that.tablesMergeCell(data);
                    that.visitClientCustomer.visitCount = that.getCount(that.visitClientCustomer.list, "visitCount");
                }, false, "#visitClientCompany");
            },
//            getList: function () {
//                var that = this;
//                $.wyui.postMethod(urlConfig.report.visitCustomer.getManagerByUserId, {
//                    "dateTime":that.dateTime,"companyId":that.companyId
//                } , function (data) {
//                    console.log(data);
//                    that.list = that.tablesMergeCell(data);
//                    that.allCount=that.getCount(that.list,"visitCount")
//                });
//            },

            isGo: function (item) {
                return true;
                if (getCurrentUser().companyName == "滚滚向前" || getCurrentUser().roleName == '销售管理经理' || getCurrentUser().id == item.managerId || getCurrentUser().roleName == '总经理' || getCurrentUser().roleName == '销售总监') {
                    return true;
                } else {
                    return false;
                }
            }
        },
        mounted: function () {
            var that = this;
            //获取前5个月
            that.getTab();
            if (!that.companyId) {
                that.companyId = getCurrentUser().companyId;
            }
            that.get_visitClientCompany();
        }

    });
</script>

</body>
</html>